#define DEBUG

namespace algo {
    const db STT_ALL = 0.01L;
    const db EDT_ALL = 0.0001L;
    const db DTT_ALL = 0.998L;
    const db EDT_SGC = 0.001L;
    const db DTT_SGC = 0.98L;
    const db RAT_SGC = 10.0L;
    void SA(Sta &ansSta, Sta::iterator ansIt, db stt) {
        Sta curSta = ansSta; db ansE = DBL_MAX, curE = ansE;
        Sta::iterator curIt = curSta.begin() + (ansIt - ansSta.begin());
        for (db T = stt; T > EDT_SGC; T *= DTT_SGC) {
            Circ oriSta = *curIt;
            curIt -> x += rnd(-width, width) * T * RAT_SGC;
            curIt -> y += rnd(-height, height) * T * RAT_SGC;
            db newE = ESgc(curSta, curIt);
            if (newE <= curE) curE = ansE = newE, *ansIt = *curIt;
            else if (exp(-(newE - curE) / T) > rnd()) curE = newE;
            else *curIt = oriSta;
        }
    }
    void SA(Sta &curSta) {
        for (db T = STT_ALL; T > EDT_ALL; T *= DTT_ALL) {
            for (auto it = curSta.begin(); it != curSta.end(); ++it)
                SA(curSta, it, T);
            std::shuffle(curSta.begin(), curSta.end(), rdIns);
        }
    }
}
